package net.xdclass.strategy;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class ShardingDBConfig {
    /**
     * 存储库编号
     */
    private static final List<String> dbFrefixList = new ArrayList<>();
    
    static {
        dbFrefixList.add("0");
        dbFrefixList.add("1");
        dbFrefixList.add("a");
    }

    /**
     * 随机获取前缀
     */
    public static String getRandomDBPrefix(String code) {
        int index = Math.abs(code.hashCode());
        //对集合进行取模
        index = index % dbFrefixList.size();
        return dbFrefixList.get(index);
    }

}
